<template>
  <div id="resourceManagement">
    <div id="tabelTitle">
      简历管理
    </div>
    <div id="table">
      <avue-crud
        v-model="form"
        :search.sync="searchForm"
        :page.sync="page"
        :data="tableData"
        :table-loading="tableLoading"
        :option="tableOption"
        @on-load="getList"
        @search-change="searchChange"
        @refresh-change="refreshChange"
        @size-change="sizeChange"
        @current-change="currentChange"
        @row-update="handleUpdate"
        @row-save="handleSave"
        @row-del="rowDel"
        @selection-change="selectionChange"
      >
        <template slot="menuLeft" slot-scope="{size}">
          <el-button type="primary" :size="size" @click="rowDel()">删除</el-button>
        </template>
        <template slot="menu" slot-scope="{row,size}">
          <el-button type="primary" :size="size" @click="look(row)">查看简历</el-button>
        </template>
      </avue-crud>
    </div>
    <el-dialog
      title="简历查看"
      :visible.sync="dialogVisible"
      width="80%">
      <iframe style="width: 100%;min-height: 600px;" :src="wrUrl" width='100%' height='100%' frameborder='1'>
      </iframe>
      <span slot="footer" class="dialog-footer">
    <el-button @click="dialogVisible = false">取 消</el-button>
    <el-button type="primary" @click="dialogVisible = false">确 定</el-button>
  </span>
    </el-dialog>
  </div>
</template>

<script>
import tableMixins from "@/mixins/tableMixin.vue"

export default {
  name: "resume",
  mixins: [tableMixins],
  data() {
    return {
      dialogVisible: false,
      form: {},
      //访问接口前缀
      url: "yuanjiu.testnew/tn-resume",
      searchForm: {},
      // 表格参数
      tableOption: {
        border: true,
        index: false,
        indexLabel: '序号',
        indexWidth: 50,
        stripe: true,
        align: 'center',
        searchMenuSpan: 8,
        labelWidth: 120,
        searchLabelWidth: 100,
        calcHeight: 300,
        dialogWidth: 900,
        menuWidth: 200,
        menu: true,
        menuAlign: 'center',
        refreshBtn: false,
        columnBtn: false,
        searchShowBtn: false,
        addBtn: true,
        selection: true,
        rowKey: "id",
        emptyBtn: true,
        editBtn: false,
        viewBtn: true,
        delBtn: false,
        emptyBtnText: "重置",
        editBtnText: "修改",
        maxHeight: 645000,
        searchSize: "medium",
        column: [
          {
            label: '简历来源',
            prop: 'sourceType',
            type: 'select',
            props: {
              label: 'name',
              value: 'code'
            },
            dicData: [
              {
                name: '系统抓取邮箱',
                code: 1
              }, {
                name: '上传',
                code: 2
              },],
            rules: [{
              required: true,
              message: "请选择简历来源",
              trigger: "change"
            }],
          },
          {
            label: "简历主题",
            prop: "subject",
            rules: [{
              required: true,
              message: "请输入简历主题",
              trigger: "blur"
            }],
          },
          {
            label: '应聘岗位',
            prop: 'jobTitle',
            rules: [{
              required: true,
              message: "请输入应聘岗位",
              trigger: "blur"
            }],
          },
          {
            label: '简历投递方式',
            prop: 'sendType',
            type: "select",
            dicUrl: '/yuanjiu.testnew/yj-config/getConfigByCode?itmCode=RESUME_SENT_TYPE',
            props: {
              label: "itmName",
              value: "itmVal",
              res: "result"
            },
            rules: [{
              required: true,
              message: "请选择简历投递方式",
              trigger: "change"
            }],
          },
          {
            label: '简历上传',
            prop: 'fileUrl',
            type: 'upload',
            multiple: true,
            hide: true,
            span: 24,
            propsHttp: {
              url: 'result',
              name:'result'
            },
            tip: '支持word、pdf文件上传',
            action: '/yuanjiu/upload/uploadImg',
            viewDisplay: false,
          },
          {
            label: '简历投递时间',
            prop: 'createTime',
            editDisplay: false, addDisplay: false,
            type: "date",
            format: 'yyyy-MM-dd',
            valueFormat: 'yyyy-MM-dd',
          },
        ]
      },
      listUrl: 'pageTnResume',
      delUrl: "deleteList",
      updateUrl: "insertOrUpdate",
      delIdList: [],
      wrUrl: ""
    }
  },
  methods: {
    //勾选获取当前数据ID
    selectionChange(list) {
      // console.log(list)
      this.delIdList = []
      list.forEach((x) => {
        this.delIdList.push(x.resumeId)
      })
    },
    look(row) {
      if (row.fileUrl) {

//获取最后一个.的位置
        let index = row.fileUrl.lastIndexOf(".");
//获取后缀
        let ext = row.fileUrl.substr(index + 1);
        if (ext == "pdf") {
          this.wrUrl = row.fileUrl
        } else {
          this.wrUrl = "https://view.officeapps.live.com/op/view.aspx?src=" + row.fileUrl
        }
      }
      else {
        this.wrUrl="/yuanjiu.testnew/tn-resume/viewResume?resumeId="+row.resumeId
      }

      this.dialogVisible = true

      // console.log(row.fileUrl)
    },

    /**
     * 新增保存
     * @param row 行数据
     * @param done 完成回调
     * @param loading 加载回调
     */
    handleSave: function (row, done, loading) {
      // console.log('row',row)
      if(row.fileUrl.length<1){
        this.$message.error('请上传简历')
        loading();
      }
      else {
        row.fileUrl = row.fileUrl[0].value
        this.$httpService.post("/" + this.url + "/" + this.addUrl, row).then(res => {
          this.$message.success('新增成功');
          this.getList();
          done();
          loading();
        }).catch(res => {
          loading();
        })
      }



    },

    /**
     * 删除
     * @param row 行数据
     * @param index 行索引
     */
    rowDel: function (row) {
      // console.log('this.delIdList',this.delIdList)
      if (this.delIdList.length == 0) {
        this.$message.error('请先选择数据');
      } else {
        this.$confirm('是否确认删除？', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.$httpService.post("/" + this.url + "/" + this.delUrl, this.delIdList).then(res => {
            this.$message.success('删除成功');
            this.getList();
          })
        })
      }
    },
  },
  mounted() {
  }
}
</script>

<style scoped>

</style>
